let PubSub = {
    events: {},
    on(type, handler) {
        let events = this.events;
        events[type] = events[type] || [];
        events[type].push(handler);
    },
    emit(type, ...datas) {
        let events = this.events;
        if (!events[type]) {
            return;
        }
        events[type].forEach(handler => handler(...datas));
    }
}

    
    
    
    =======
    
    
const urls = [
    "http://url1",
    "http://url2",
    "http://url3"
];

let makeAjasCall =  url => {
    PubSub.emit('ajaxEnd', result);
}

let subscribe = url => {
    let index = 0;
    PubSub.on("ajaxEnd", result => {
        result = JSON.parse(result);
        
        if (urls[++index]) {
            makeAjaxCall(`${urls[index]} ? q = ${result.query}`);
        }
    });
    makeAjaxCall(urls[0]);
}